#coding=utf-8
"""
Author:王霄
Time:2025/3/3 14:57
website:https://duoceshi.net
"""
import sys
sys.path.append('..')
import openpyxl
from utiles.handle_path import *
import os
class Handle_Excel(object):
    def __init__(self,filename,sheet_name):
        self.filename=filename
        self.sheet_name=sheet_name
    def open(self):
        self.wb=openpyxl.load_workbook(self.filename)
        self.sh=self.wb[self.sheet_name]
    def read_data(self):
        self.open()
        datas=list(self.sh.rows)
        title=[i.value for i in datas[0]]
        cases=[]
        for j in datas[1:]:
            values=[k.value for k in j]
            case=dict(zip(title,values))
            cases.append(case)
        return cases
    def write_excel(self,row,col,value):
        self.open()
        self.sh.cell(row,col,value)
        self.wb.save(self.filename)
if __name__ == '__main__':
    path=os.path.join(data_path,'apicase.xlsx')
    read_excel=Handle_Excel(path,'login')
    print(read_excel.read_data())
    read_excel.write_excel(2,8,'通过')
